import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/global.less'
import VueQuillEditor from 'vue-quill-editor'
// import 'quill/dist/quill.core.css'
// import 'quill/dist/quill.snow.css'
// import 'quill/dist/quill.bubble.css'
import dayjs from 'dayjs'

Vue.use(VueQuillEditor)

axios.defaults.baseURL = 'http://www.liulongbin.top:3008'
Vue.prototype.$http = axios

axios.interceptors.request.use(function (config) {
  if (config.url.startsWith('/my')) {
    config.headers.Authorization = store.state.token
  }
  return config
}, function (error) {
  return Promise.reject(error)
})

axios.interceptors.response.use(function (response) {
  return response
}, function (error) {
  if (error.response.status === 401) {
    store.commit('updateToken', '')
    router.push('/login')
  }
  return Promise.reject(error)
})

Vue.filter('dateFormat', (str) => {
  return dayjs(str).format('YYYY-MM-DD HH:mm:ss')
})

Vue.config.productionTip = false

Vue.use(ElementUI)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
